<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <!-- <a-col :span="24">
            <a-form-model-item label="单井ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wellId">
              <a-input v-model="model.wellId" placeholder="请输入单井ID"  ></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="组织机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgId">
              <!-- <a-input v-model="model.orgId" placeholder="请输入组织机构ID"  ></a-input> -->
              <j-tree-select placeholder="请选择组织机构" v-model="model.orgId" dict="sys_depart,depart_name,id" pid-field="parent_id" ></j-tree-select>
            </a-form-model-item>
          </a-col>

          <a-col :span="24">
            <a-form-model-item label="单井名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wellName">
<!--              <me-dict-select-tag type="list" v-model="model.wellName" dictCode="cd_well,well_common_name,well_id" placeholder="请选择单井名称" v-on:change="haha"  />-->
              <j-search-select-tag   v-model="model.id" dict="cd_well,well_common_name,well_id" placeholder="请选择单井名称" v-on:change="haha" :async="true"  :pageSize="20" :disabled="isadd === false" />

            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经度坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="x">
              <a-input-number v-model="model.x" placeholder="请输入经度坐标" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="维度坐标" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="y">
              <a-input-number v-model="model.y" placeholder="请输入维度坐标" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import {filterDictTextByCache} from '@/components/dict/JDictSelectUtil'
  export default {

    name: 'CommWellForm',
    components: {
    },
    props:[
        'isxianshi',
        {



      //表单禁用

      disabled: {
        type: Boolean,
        default:true,
        required: false,

      }
    },
    ],
    data () {
      return {

        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          //  wellId: [
          //     { required: true, message: '请输入单井ID!'},
          //  ],
        },
        url: {
          add: "/commWell/commWell/add",
          edit: "/commWell/commWell/edit",
          queryById: "/commWell/commWell/queryById"
        },

       isadd:false,



      }

    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));

    },
    methods: {
        creat(){
            console.log("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"+isxianshi);
        },

        haha (x,y) {

            console.log(x);
            console.log(y);
            this.model.id=x;
            this.model.wellName=y;

        } ,
      add () {
        this.edit(this.modelDefault);
        this.isadd=true;
      },
      edit (record) {


        this.model = Object.assign({}, record);
          // console.log(model);
        this.visible = true;

      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            // if(!this.model.id){
            //   httpurl+=this.url.add;
            //   method = 'post';
            // }else{
            //   httpurl+=this.url.edit;
            //    method = 'put';
            // }

              if (this.isadd){
                  httpurl+=this.url.add;
                   method = 'post';
                  // this.isxianshi = false;
              }else {
                  httpurl+=this.url.edit;
                     method = 'put';
              }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              this.isadd = false;


            })
          }
         
        })
      },
    }
  }
</script>